package com.ttj.controller.purchaser;


import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.ttj.domain.oracle.OrderRec;
import com.ttj.service.OrderRecService;
import com.ttj.vo.BaseRes;
import com.ttj.vo.OrderRecVo;

/**
 * 回收管理模块
 * 
 * @author ASia
 *
 */
@Controller
@RequestMapping("purchaser/orderRec")
public class OrderRecController {

	private static Logger logger = LoggerFactory.getLogger(OrderRecController.class);
	
	@Resource
	private OrderRecService orderRec;
	
	/**
	 * 首页ok
	 * @return
	 */
	@RequestMapping(value = "/home", method = RequestMethod.GET)
	@ResponseBody
	public BaseRes<OrderRecVo> index(String username) {
		logger.debug("{}",username);
		return orderRec.index(username);
	}

	/**
	 * 回收管理(未回复、未完成)
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/recList", method = RequestMethod.GET)
	@ResponseBody
	public BaseRes<List<OrderRec>> orderList(String username, Integer oStatus) {
		logger.debug("{}",username,oStatus);
		return orderRec.orderRecList(username,oStatus);
	}

	/**
	 * 回收管理(当前月已完成订单)
	 * @return
	 */
	@RequestMapping(value = "/completed", method = RequestMethod.GET)
	@ResponseBody
	public BaseRes<List<OrderRec>> orderListCompleted(String username) {
		logger.debug("{}",username);
		return orderRec.orderRecListCompleted(username);
	}

	/**
	 * 订单详情
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/detail", method = RequestMethod.GET)
	@ResponseBody
	public BaseRes<List<OrderRecVo>> orderDetail(Long orderId) {
		logger.debug("{}",orderId);
		return orderRec.getOrderRecDetail(orderId);
	}

	/**
	 * 订单品类列表
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/recDetailList", method = RequestMethod.GET)
	@ResponseBody
	public BaseRes<List<OrderRecVo>> recDetailList(Long orderId) {
		logger.debug("{}",orderId);
		return orderRec.getOrderRecDetailList(orderId);
	}

	/**
	 * 回复回收时间
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/reply", method = RequestMethod.GET)
	@ResponseBody
	public int reply(Long orderId,String replyTime) {
		logger.debug("{}",orderId,replyTime);
		return orderRec.reply(orderId,replyTime);
	}

	/**
	 * 工作日志
	 * @return
	 */
	@RequestMapping(value = "/dailylog", method = RequestMethod.GET)
	@ResponseBody
	public BaseRes<Map<String,Object>> dailylog(String username,String begintime,String endtime) {	
		logger.debug("{}",username,begintime,endtime);
		return orderRec.dailylog(username,begintime,endtime);
	}
	
	/**
	 * 个人回收订单
	 * @param json
	 * @param strings
	 * @return
	 */
	@RequestMapping(value="/create",method=RequestMethod.GET)
	@ResponseBody
	public Map<String,Object> createRec(String json){
		Gson gson = new Gson();
		Type type = new TypeToken<OrderRecVo>(){}.getType();
		OrderRecVo recList = gson.fromJson(json, type);
		logger.debug("{}",json);
		return orderRec.createRec(recList);
	}
	
	/**
	 * 处理app订单
	 * @param json
	 * @return
	 */
	@RequestMapping(value="/update",method=RequestMethod.GET)
	@ResponseBody
	public Map<String,Object> updateRec(String json){
		Gson gson = new Gson();
		Type type = new TypeToken<OrderRecVo>(){}.getType();
		OrderRecVo recList = gson.fromJson(json, type);
		logger.debug("{}",json);
		return orderRec.updateRec(recList);
	}
	
	
}
